#encoding=utf8
'''
Created on 2012-9-24

@author: Administrator
'''
from models.Singleton import Singleton
#try:
#    import redis
#except:
#    pass
CacheObject = {}
'''
class WorkMemRedis(Singleton):
    def __init__(self):
        global RedisConnect
        
        if RedisConnect == None:
            #core.oliyo.com=>202.96.246.196x 
            RedisConnect = redis.StrictRedis(host='core.oliyo.com', port=11220, db=2)
    def setData(self, keyName, data):
        pass
    def getData(self, keyName, data):
        pass
    def saveData(self,):
        pass
'''
class WorkMemMemcache(Singleton):
    pass
class WorkMemFile(Singleton):
    pass

class WorkMem(Singleton):
    '''
    u'内存工作类
    '''
    
    def __init__(self,memName):

        
        if CacheObject==None:
            CacheObject = {}
        self.__cacheHandle[memName] = CacheObject
    def __str__(self):
        return self    
    def setData(self, keyName, data):
        '''
        u'当data加入到字典中，键名为keyName
        '''
        self.__cacheHandle[keyName]=data
    def getData(self, keyName):
        '''
        u'根据keyName得到字典中的value值
        '''
        if keyName in self.__cacheHandle:
            return self.__cacheHandle[keyName]
        else:
            return False
    def delData(self, keyName):
        '''
        u'根据指定keyName删除
        '''
        del(self.__cacheHandle[keyName])
    def checkHaveExist(self,keyName):
        if keyName in self.__cacheHandle:
            return True
        else:
            return False
    def flush(self,): 
        '''
        u'清除缓存
        '''
        self.__cacheHandle.clear()